{extend name="base" /}
{block name='content'}
<blockquote class="layui-elem-quote">用户列表</blockquote>
    <div class="layui-card">
        <div class="layui-card-header" style="padding: 15px;">
          <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-green" id="add">添加用户</a> 
        </div>
        <div class="layui-card-body">
          <form class="layui-form">
          <table class="layui-table">
            <thead>
              <tr>
                <th>ID</th>
                <th>头像</th>
                <th>昵称</th>
                <th>性别</th>
                <th>手机号</th>
                <th>状态</th>
                <th>创建时间</th>
                <th>更新时间</th>
                <th>操作</th>
              </tr> 
            </thead>
            <tbody>
              {foreach $list as $vo}
              <tr>
                <td>{$vo.id}</td>
                <td><img src="{$vo.avatar}" class="layui-upimg"></td>
                <td>{$vo.nickname}</td>
                <td>{$vo.gender}</td>
                <td>{$vo.phone}</td>
                <td>
                    {empty name='$vo.status'}
                      <span class="layui-font-red">禁用</span>
                    {else/}  
                      <span class="layui-font-green">启用</span>
                    {/empty}
                </td>
                <td>{$vo.create_time}</td>
                <td>{$vo.update_time}</td>
                <td>
                  <a class="layui-btn layui-btn-sm edit" data-id="{$vo.id}">编辑</a>
                  <a class="layui-btn layui-btn-sm layui-btn-danger" href="{:url('admin/user/delete',['id' => $vo.id])}">删除</a>
                </td>
              </tr>
              {/foreach}
           
            </tbody>
          </table>
        </form>
        </div>
    </div>

    <script>
      layui.use(['layer','form'], function(){
         var form = layui.form,layer = layui.layer,$ = layui.jquery;
         $('#add').click(function(){
             layer.open({
             title:['添加用户'],  
             type:2,
             area:['600px','800px'],
             content: '/admin/user/create',
           })
         });
   
         $('.edit').click(function(){
            let id = $(this).attr('data-id');
             layer.open({
             title:['添加用户'],  
             type:2,
             area:['600px','800px'],
             content: '/admin/user/edit?id='+id,
           })
         });

         $('.switch').on('click',function(){
          let status = $(this).attr('data-status'), id = $(this).attr('data-id');
          $.post('/admin/user/switch',{status:status,id:id},function(res){
                if(res.code == 1){
                  layer.msg(res.msg,{icon:1});
                  parent.$.pjax.reload('#main',{fragment: '#main'});
                  return false;
                }

                layer.msg(res.msg,{icon:2});
          });

        });
        
   });              
   </script>
{/block}